#
# Amontec JTAGkey
#
# http://www.amontec.com/jtagkey.shtml
#

interface ftdi
ftdi_device_desc "Amontec JTAGkey"
ftdi_vid_pid 0x0403 0xcff8

ftdi_layout_init 0x0c08 0x0f1b
ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400
ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800

reset_config trst_push_pull srst_push_pull trst_and_srst
adapter_khz 5
transport select jtag

adapter_nsrst_delay 200
#jtag_ntrst_delay 200

jtag newtap bk3231 cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x15968001
target create bk3231.cpu arm966e -endian little -chain-position bk3231.cpu

# don't activate work area, because execution from ram is not possible!
#bk3231.cpu configure -work-area-phys 0x00403F00 -work-area-size 0x100
bk3231.cpu configure -event reset-start {
	echo "reset start"
	adapter_khz 5
	global cpu_halted
	set cpu_halted 0
}

bk3231.cpu configure -event reset-init {
	echo "reset init"
	# enable 16 MHz clock
	mww 0x920000 0x01
	mww 0x920004 0x00

	adapter_khz 1000
	arm7_9 dcc_downloads enable
	arm7_9 fast_memory_access enable
}

bk3231.cpu configure -event halted {
	echo "target halted"
	global cpu_halted
	set cpu_halted 1
}

bk3231.cpu configure -event resumed {
	echo "target resumed"
	global cpu_halted
	set cpu_halted 0
}

source bk3231_flash.tcl

telnet_port 4444

init

#reset init
